<?php 
	$idUsuario = REPLACE_Injection($_GET["id"]);
	
	$query = new mysqlQuery("tournament", "", "usuarios", "", "`id`='".$idUsuario."'", "", "");
	$query->execute();
	if($query->getCount() == 1){
		$row = $query->next();
				
		$cacheFile = "cache/user/profile-".$idUsuario.".dat";
		if(@file_exists($cacheFile)){
			$cacheTime = @filemtime($cacheFile);
		}else{
			$cacheTime = 0;
		}
		
		$regenerate = @$_GET["regenerate"];
		$tracecache = @$_GET["tracecache"];
		
		if($tracecache && isAdmin()){
			$modificationTime = time() - $cacheTime;
			echo '<div id="status">Generated: '.tournamentGenerationTime($modificationTime).'. Regeneration in: 
				'.tournamentGenerationTime(CACHE_TIME - $modificationTime).'.</div>';
		}
		
		@clearstatcache();
		if(((time() - CACHE_TIME) < $cacheTime) && !(isAdmin() && $regenerate)){
			@readfile($cacheFile);
			exit();
		}
		
		ob_start();
		?>		
		<div id="all">
			<h1 class="profile-title"><?php echo $row["usuario"]." (".$row["jugador"].")";?></h1>
			<div id="left">
				<div class="container">
					<div class="container-title">Finished Matches</div>
					<img src="img/tournaments-finished.jpg" width="444" height="80" />
				</div>
				<div class="container" style="border:0;">
					<?php mostrarPartidosTerminadosUsuario($idUsuario);?>
				</div>
				<div class="container">
					<div class="container-title">Finished Tournaments</div>
					<img src="img/tournaments-finished-tournaments.jpg" width="444" height="80" />		
				</div>		
				<div class="container" style="border:0;">
					<?php mostrarTorneosTerminadosUsuario($idUsuario);?>
				</div>
				<div class="container">
					<div class="container-title">Current Tournaments</div>
					<img src="img/tournaments-current-tournaments.jpg" width="444" height="80" />		
				</div>
				<div class="container" style="border:0;">
					<?php mostrarTorneosActivosUsuario($idUsuario);?>			
				</div>
				<div class="container">
					<div class="container-title">Current Tournament Inscriptions</div>
					<img src="img/tournaments-inscription-tournaments.jpg" width="444" height="80" />		
				</div>
				<div class="container" style="border:0;">
					<?php mostrarTorneosInscritosUsuario($idUsuario);?>			
				</div>
			</div>
			<div id="right">
				<div class="container">
					<div class="container-title">Player Statistics</div>
					<img src="img/tournaments-stats.jpg" width="444" height="80" />		
				</div>
				<div class="container" style="border:0;">
					<?php mostrarEstadisticasJugador($idUsuario);?>
				</div>
				<div class="container">
					<div class="container-title">Current Matches</div>
					<img src="img/tournaments-inscription.jpg" width="444" height="80" />
				</div>
				<div class="container">
					<?php mostrarPartidosActivosUsuario($idUsuario);?>
				</div>
			</div>
		</div>
		<?php
		$fw = @fopen($cacheFile, "w");
		@fwrite($fw, ob_get_contents());
		@fclose($fw);
		ob_end_flush();
		
	}else{
		?>
		<div id="all">
			<div id="error">
				User does not exist
			</div>
		</div>
		<?php
	}
?>